home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
auto_cad
/
vol2no4.lzh
/
CSPLINE5.LSP
< prev
next >
Wrap
Text File
|
1987-05-18
|
5KB
|
193 lines
;5 pt. Cubic Spline
; by TIMOTHY L. GRANT c. 1987
;
(defun C:SPLINE ()
(defun CMDPROMPT ()
(defun *error* (st)
(setq *error* nil)
(princ))
(quit))
;
(SETVAR "CMDECHO" 0)
(SETQ N 5)
(SETQ P1 (GETPOINT "\nPick point:"))
(SETQ P2 (GETPOINT "\nPick point:"))
(SETQ P3 (GETPOINT "\nPick point:"))
(SETQ P4 (GETPOINT "\nPick point:"))
(SETQ P5 (GETPOINT "\nPick point:"))
(SETQ X1 (CAR P1))
(SETQ Y1 (CADR P1))
(SETQ X2 (CAR P2))
(SETQ Y2 (CADR P2))
(SETQ X3 (CAR P3))
(SETQ Y3 (CADR P3))
(SETQ X4 (CAR P4))
(SETQ Y4 (CADR P4))
(SETQ X5 (CAR P5))
(SETQ Y5 (CADR P5))
(SETQ NSPLINE 20) ; # pts. on spline
(SETQ T1 0)
(SETQ T2 (+ T1 (DISTANCE P1 P2)))
(SETQ T3 (+ T2 (DISTANCE P2 P3)))
(SETQ T4 (+ T3 (DISTANCE P3 P4)))
(SETQ T5 (+ T4 (DISTANCE P4 P5)))
;
(SETQ J (GETREAL "\n Beginning Curvature Coeff.:"))
(SETQ K (GETREAL "\n Ending Curvature Coeff.:"))
; Compute spline on t,x & t,y
; 1st differences
(SETQ H1 (- T2 T1))
(SETQ H2 (- T3 T2))
(SETQ H3 (- T4 T3))
(SETQ H4 (- T5 T4))
(SETQ C2 (+ (* (+ 2 J) H1) (* 2 H2)))
(SETQ C3 (* 2 (+ H2 H3)))
(SETQ C4 (+ (* (+ 2 K) H4) (* 2 H3)))
;
(SETQ DX2 (* 6 (- (/ (- X3 X2) H2) (/ (- X2 X1) H1))))
(SETQ DX3 (* 6 (- (/ (- X4 X3) H3) (/ (- X3 X2) H2))))
(SETQ DX4 (* 6 (- (/ (- X5 X4) H4) (/ (- X4 X3) H3))))
;
(SETQ DY2 (* 6 (- (/ (- Y3 Y2) H2) (/ (- Y2 Y1) H1))))
(SETQ DY3 (* 6 (- (/ (- Y4 Y3) H3) (/ (- Y3 Y2) H2))))
(SETQ DY4 (* 6 (- (/ (- Y5 Y4) H4) (/ (- Y4 Y3) H3))))
;
(SETQ C3 (- C3 (/ (* H2 H2) C2)))
(SETQ C4 (- C4 (/ (* H3 H3) C3)))
(SETQ DX3 (- DX3 (/ (* DX2 H2) C2)))
(SETQ DX4 (- DX4 (/ (* DX3 H3) C3)))
(SETQ DY3 (- DY3 (/ (* DY2 H2) C2)))
(SETQ DY4 (- DY4 (/ (* DY3 H3) C3)))
;
(SETQ GX4 (/ DX4 C4))
(SETQ GX3 (/ (- DX3 (* H3 GX4)) C3))
(SETQ GX2 (/ (- DX2 (* H2 GX3)) C2))
(SETQ GX1 (* J GX2))
(SETQ GX5 (* K GX4))
;
(SETQ GY4 (/ DY4 C4))
(SETQ GY3 (/ (- DY3 (* H3 GY4)) C3))
(SETQ GY2 (/ (- DY2 (* H2 GY3)) C2))
(SETQ GY1 (* J GY2))
(SETQ GY5 (* K GY4))
;
(SETQ DT (/ T5 NSPLINE))
(SETQ WT 0)
(SETQ IX1 X1)
(SETQ IY1 Y1)
; compute and plot interpolated values
(WHILE (<= WT T2) ; interval T1 - T2
(SETQ H (- WT T1))
(SETQ K1 (- T2 WT))
(SETQ K1C (* K1 K1 K1))
(SETQ K2 (- WT T1))
(SETQ K2C (* K2 K2 K2))
(SETQ IX2 (/ (* GX1 (- (/ K1C H1) (* H1 K1))) 6))
(SETQ IX2 (+ IX2 (/ (* GX2 (- (/ K2C H1)(* H1 K2))) 6)))
(SETQ IX2 (+ IX2 (* X1 (/ K1 H1))))
(SETQ IX2 (+ IX2 (* X2 (/ K2 H1))))
;
(SETQ IY2 (/ (* GY1 (- (/ K1C H1) (* H1 K1))) 6))
(SETQ IY2 (+ IY2 (/ (* GY2 (- (/ K2C H1)(* H1 K2))) 6)))
(SETQ IY2 (+ IY2 (* Y1 (/ K1 H1))))
(SETQ IY2 (+ IY2 (* Y2 (/ K2 H1))))
;
(SETQ S1 (LIST IX1 IY1))
(SETQ S2 (LIST ix2 iy2))
(COMMAND "LINE" S1 S2 "")
; (COMMAND "")
;
(SETQ IX1 IX2)
(SETQ IY1 IY2)
;
(SETQ WT (+ WT DT))
) ;wend
;
(WHILE (<= WT T3) ; interval T2 - T3
(SETQ H (- WT T2))
(SETQ K1 (- T3 WT))
(SETQ K1C (* K1 K1 K1))
(SETQ K2 (- WT T2))
(SETQ K2C (* K2 K2 K2))
(SETQ IX2 (/ (* GX2 (- (/ K1C H2) (* H2 K1))) 6))
(SETQ IX2 (+ IX2 (/ (* GX3 (- (/ K2C H2)(* H2 K2))) 6)))
(SETQ IX2 (+ IX2 (* X2 (/ K1 H2))))
(SETQ IX2 (+ IX2 (* X3 (/ K2 H2))))
;
(SETQ IY2 (/ (* GY2 (- (/ K1C H2) (* H2 K1))) 6))
(SETQ IY2 (+ IY2 (/ (* GY3 (- (/ K2C H2)(* H2 K2))) 6)))
(SETQ IY2 (+ IY2 (* Y2 (/ K1 H2))))
(SETQ IY2 (+ IY2 (* Y3 (/ K2 H2))))
;
(SETQ S1 (LIST IX1 IY1))
(SETQ S2 (LIST IX2 IY2))
(COMMAND "LINE" S1 S2 "")
; (COMMAND "")
;
(SETQ IX1 IX2)
(SETQ IY1 IY2)
;
(SETQ WT (+ WT DT))
) ;wend
;
(WHILE (<= WT T4) ; interval T3 - T4
(SETQ H (- WT T3))
(SETQ K1 (- T4 WT))
(SETQ K1C (* K1 K1 K1))
(SETQ K2 (- WT T3))
(SETQ K2C (* K2 K2 K2))
(SETQ IX2 (/ (* GX3 (- (/ K1C H3) (* H3 K1))) 6))
(SETQ IX2 (+ IX2 (/ (* GX4 (- (/ K2C H3)(* H3 K2))) 6)))
(SETQ IX2 (+ IX2 (* X3 (/ K1 H3))))
(SETQ IX2 (+ IX2 (* X4 (/ K2 H3))))
;
(SETQ IY2 (/ (* GY3 (- (/ K1C H3) (* H3 K1))) 6))
(SETQ IY2 (+ IY2 (/ (* GY4 (- (/ K2C H3)(* H3 K2))) 6)))
(SETQ IY2 (+ IY2 (* Y3 (/ K1 H3))))
(SETQ IY2 (+ IY2 (* Y4 (/ K2 H3))))
;
(SETQ S1 (LIST IX1 IY1))
(SETQ S2 (LIST IX2 IY2))
(COMMAND "LINE" S1 S2 "")
; (COMMAND "")
;
(SETQ IX1 IX2)
(SETQ IY1 IY2)
;
(SETQ WT (+ WT DT))
) ;wend
;
(WHILE (<= WT T5) ; interval T4 - T5
(SETQ H (- WT T4))
(SETQ K1 (- T5 WT))
(SETQ K1C (* K1 K1 K1))
(SETQ K2 (- WT T4))
(SETQ K2C (* K2 K2 K2))
(SETQ IX2 (/ (* GX4 (- (/ K1C H4) (* H4 K1))) 6))
(SETQ IX2 (+ IX2 (/ (* GX5 (- (/ K2C H4)(* H4 K2))) 6)))
(SETQ IX2 (+ IX2 (* X4 (/ K1 H4))))
(SETQ IX2 (+ IX2 (* X5 (/ K2 H4))))
;
(SETQ IY2 (/ (* GY4 (- (/ K1C H4) (* H4 K1))) 6))
(SETQ IY2 (+ IY2 (/ (* GY5 (- (/ K2C H4)(* H4 K2))) 6)))
(SETQ IY2 (+ IY2 (* Y4 (/ K1 H4))))
(SETQ IY2 (+ IY2 (* Y5 (/ K2 H4))))
;
(SETQ S1 (LIST IX1 IY1))
(SETQ S2 (LIST IX2 IY2))
(COMMAND "LINE" S1 S2 "")
; (COMMAND "")
;
(SETQ IX1 IX2)
(SETQ IY1 IY2)
;
(SETQ WT (+ WT DT))
) ;wend
;
(SETQ S1 (LIST IX1 IY1))
(COMMAND "LINE" S1 P5 "")
; (COMMAND "")
;
(GC)
(CMDPROMPT))